import {
  Component,
  OnInit,
  OnChanges,
  SimpleChanges,
  Input,
  Output,
  EventEmitter
} from '@angular/core';
import {
  Meta,
  Title
} from '@angular/platform-browser';
import {
  FormsModule
} from '@angular/forms';
import { Pipe, PipeTransform } from '@angular/core';

@Component({
  selector: 'app-home-page',
  templateUrl: './home-page.component.html',
  styleUrls: ['./home-page.component.scss']
})
export class HomePageComponent implements OnInit, OnChanges {
  // Excel cells:
  // Common
  @Input() c3:number=200;
  @Input() c4:number=160;

  // 案例一
  @Input() e9:number=60;
  @Input() e10:number=800;

  @Input() c16:number=40;
  @Input() c17:number=40;
  @Input() c18:number=40;
  @Input() c19:number=1.5;
  @Input() c20:number=6;
  @Input() c21:number=12;
  @Input() c22:number=30;
  @Input() c23:number=20;
  @Input() c24:number=200;

  @Output() e12:number;
  @Output() e13:number;
  @Output() e14:number;
  @Output() e16:number;
  @Output() e17:number;
  @Output() e18:number;
  @Output() e19:number;
  @Output() e20:number;
  @Output() e21:number;
  @Output() e22:number;
  @Output() e23:number;
  @Output() e24:number;
  @Output() e25:number;

  // 案例二
  @Input() j9:number=70;
  @Input() j10:number=686;

  @Input() h16:number=40;
  @Input() h17:number=40;
  @Input() h18:number=40;
  @Input() h19:number=1.5;
  @Input() h20:number=6;
  @Input() h21:number=12;
  @Input() h22:number=35;
  @Input() h23:number=10;
  @Input() h24:number=100;

  @Output() j12:number;
  @Output() j13:number;
  @Output() j14:number;
  @Output() j16:number;
  @Output() j17:number;
  @Output() j18:number;
  @Output() j19:number;
  @Output() j20:number;
  @Output() j21:number;
  @Output() j22:number;
  @Output() j23:number;
  @Output() j24:number;
  @Output() j25:number;

  // 差异
  @Input() m27:number=80;
  @Input() m28:number=20;

  @Output() o9:number;
  @Output() o10:number;

  @Output() o12:number;
  @Output() o13:number;
  @Output() o14:number;
  @Output() o16:number;
  @Output() o17:number;
  @Output() o18:number;
  @Output() o19:number;
  @Output() o20:number;
  @Output() o21:number;
  @Output() o22:number;
  @Output() o23:number;
  @Output() o24:number;
  @Output() o25:number;

  @Output() o27:number;
  @Output() o28:number;
  @Output() o29:number;


  constructor(){
    this.recal();
  }
  ngOnInit(){
    // console.log("ngOninit");
  }

  ngOnChanges(changes: SimpleChanges){
    // tslint:disable-next-line:forin
    // console.log("ngOnChanges");
  }

  recal(){
    // console.log('recal');
    // 案例一
    this.e12 = parseFloat((this.e9/100 * this.e10).toFixed(2));
    this.e13 = parseFloat((this.c3 * this.e9/100 * 365).toFixed(2));
    this.e14 = parseFloat((this.e13 * this.e10).toFixed(2));
    this.e16 = parseFloat((this.c16 * this.e13).toFixed(2));
    this.e17 = parseFloat((this.c17 * this.e13).toFixed(2));
    this.e18 = parseFloat((this.c18 * this.e13).toFixed(2));
    this.e19 = parseFloat((this.c19/100 * this.e14).toFixed(2));
    this.e20 = parseFloat((this.c20/100 * this.e14).toFixed(2));
    this.e21 = parseFloat((this.c21/100 * this.c22/100 * this.e14).toFixed(2));
    this.e23 = parseFloat((this.c23 * this.e13).toFixed(2));
    this.e24 = parseFloat((this.c24 * this.c4).toFixed(2));
    this.e25 = parseFloat((this.e16 + this.e17 + this.e18 + 
               this.e19 + this.e20 + this.e21 + 
               this.e23 + this.e24).toFixed(2));

    // 案例二
    this.j12 = parseFloat((this.j9/100 * this.j10).toFixed(2));
    this.j13 = parseFloat((this.c3 * this.j9/100 * 365).toFixed(2));
    this.j14 = parseFloat((this.j13 * this.j10).toFixed(2));
    this.j16 = parseFloat((this.h16 * this.j13).toFixed(2));
    this.j17 = parseFloat((this.h17 * this.j13).toFixed(2));
    this.j18 = parseFloat((this.h18 * this.j13).toFixed(2));
    this.j19 = parseFloat((this.h19/100 * this.j14).toFixed(2));
    this.j20 = parseFloat((this.h20/100 * this.j14).toFixed(2));
    this.j21 = parseFloat((this.h21/100 * this.h22/100 * this.j14).toFixed(2));
    this.j23 = parseFloat((this.h23 * this.j13).toFixed(2));
    this.j24 = parseFloat((this.h24 * this.c4).toFixed(2));
    this.j25 = parseFloat((this.j16 + this.j17 + this.j18 + 
               this.j19 + this.j20 + this.j21 + 
               this.j23 + this.j24).toFixed(2));

    // 差异
    this.o9 = parseFloat((this.j9 - this.e9).toFixed(2));
    this.o10 = parseFloat((this.j10 - this.e10).toFixed(2));
    this.o12 = parseFloat((this.j12 - this.e12).toFixed(2));
    this.o13 = parseFloat((this.j13 - this.e13).toFixed(2));
    this.o14 = parseFloat((this.j14 - this.e14).toFixed(2));
    this.o16 = parseFloat((this.j16 - this.e16).toFixed(2));
    this.o17 = parseFloat((this.j17 - this.e17).toFixed(2));
    this.o18 = parseFloat((this.j18 - this.e18).toFixed(2));
    this.o19 = parseFloat((this.j19 - this.e19).toFixed(2));
    this.o20 = parseFloat((this.j20 - this.e20).toFixed(2));
    this.o21 = parseFloat((this.j21 - this.e21).toFixed(2));
    this.o23 = parseFloat((this.j23 - this.e23).toFixed(2));
    this.o24 = parseFloat((this.j24 - this.e24).toFixed(2));
    this.o25 = parseFloat((this.j25 - this.e25).toFixed(2));

    this.o27 = parseFloat((this.m27 * this.o13).toFixed(2));
    this.o28 = parseFloat((this.o27 * this.m28/100).toFixed(2));
    this.o29 = parseFloat((this.o14 - this.o25 + this.o28).toFixed(2));
  }
}
